package com.zzyl.controller;

import cn.hutool.core.bean.BeanUtil;
import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.entity.NursingProject;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import static com.zzyl.base.ResponseResult.success;

@RestController
@RequestMapping("/nursing_project")
public class NursingProjectController extends BaseController{
    @Autowired
    private NursingProjectService nursingProjectService;

    /**
     * 按条件分页查询
     * @param name
     * @param status
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping
    public ResponseResult<PageResponse<NursingProjectVo>> getByPage(
           @RequestParam(value = "name",required = false) String name,
           @RequestParam(value = "status",required = false) Integer status,
           @RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
           @RequestParam(value = "pageSize",defaultValue = "10") Integer pageSize
    ){
        PageResponse<NursingProjectVo> page = nursingProjectService.getByPage(name, status, pageNum, pageSize);

        return success(page);
    }

    /**
     * 新增
     * @param nursingProjectDto
     * @return
     */
    @PostMapping
    public ResponseResult add(@RequestBody NursingProjectDto nursingProjectDto){

        nursingProjectService.add(nursingProjectDto);
       return success();
    }

    /**
     * 按Id查询
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public ResponseResult<NursingProjectVo> getById(@PathVariable("id") Long id){
       NursingProjectVo nursingProjectVo = nursingProjectService.getById(id);
       return success(nursingProjectVo);
    }

    /**
     * 更新护理项目
     * @param nursingProjectDto
     * @return
     */
    @PutMapping
    public ResponseResult update(@RequestBody NursingProjectDto nursingProjectDto){
        nursingProjectService.update(nursingProjectDto);
        return success();
    }
    @DeleteMapping("/{id}")
    public ResponseResult deleteById(
            @PathVariable("id") Long id) {
        NursingProjectVo nursingProjectVO = nursingProjectService.getById(id);
        if (nursingProjectVO == null) {
            return ResponseResult.error();
        }
        nursingProjectService.deleteById(id);
        return ResponseResult.success();
    }
}
